package com.hcc.gateway.app.filter;

import com.hcc.gateway.app.constant.HccGatewayAppConstant;
import com.hcc.gateway.netty.context.GatewayExchange;
import com.hcc.gateway.netty.filter.GatewayFilter;
import com.hcc.gateway.netty.filter.GatewayFilterChain;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.UUID;

/**
 * GenerateTraceIdFilter
 *
 * @author shengjun.hu
 * @date 2021/12/27
 */
@Slf4j
@Component
public class GenerateTraceIdFilter implements GatewayFilter {

    @Override
    public int getOrder() {
        return 10;
    }

    @Override
    public void filter(GatewayExchange exchange, GatewayFilterChain chain) {
        log.info("进入GenerateTraceIdFilter !");
        String traceId = UUID.randomUUID().toString().replaceAll("-", "");
        exchange.addAttribute(HccGatewayAppConstant.HCC_TRACE_ID, traceId);
        chain.filter(exchange);
    }

}
